﻿using System;
using System.Reflection;
using Ue.CQRS.Events;

namespace Ue.CQRS.DistributionManager
{
    /// <summary>
    /// 事件分发器
    /// </summary>
    public interface IDistributor
    {
        /// <summary>
        /// 消息开始分发触发事件
        /// </summary>
        event EventHandler<DispatchEventArgs> Dispatching;
        /// <summary>
        /// 消息分发失败触发事件
        /// </summary>
        event EventHandler<DispatchEventArgs> DispatchFailed;
        /// <summary>
        /// 消息分发成功触发事件
        /// </summary>
        event EventHandler<DispatchEventArgs> Dispatched;


        /// <summary>
        /// 消息订阅
        /// </summary>
        /// <typeparam name="TEventArgs">消息传递的数据</typeparam>
        /// <param name="handler"></param>
        void Register(string eventName, Action<IEvent> handler);

        /// <summary>
        /// 消息分发
        /// </summary>
        void Dispatch(IEvent @event);
    }
}
